package control.panel
{
	import flash.display.DisplayObject;
	
	import global.GameState;
	
	import model.load.DisplayObjectLoadMessage;
	import model.load.XmlLoadMessage;
	
	import utils.StringUtils;
	
	import view.panel.RewardPanel;
	
	public class RewardPanelControl extends PanelControl
	{
		private var loadMsg:DisplayObjectLoadMessage;
		private var loadXmlMsg:XmlLoadMessage;
		
		public function RewardPanelControl()
		{
			initPanel();
		}

		private function onVeryCodeComplete(target:DisplayObject):void
		{
			_model.traceManager.out("verifyCode target:",target);
			_view.rewardPanel.addVeryCode(target);
			
		}
		
		private function initPanel():void
		{
			_view.rewardPanel = new RewardPanel(this);
			
		}	
		
		private function onSendBack(content:XML,type:int):void
		{
			_control.alertPanelControl.close();
			_model.traceManager.out("verifyCode money:" + content.@des.toString());
			switch(content.@des.toString())
			{
				case "-2":
					_view.rewardPanel.updateHint("验证码错误,请重新输入。");
					break;
				case "-1":
					_control.playerInfoModulControl.disableReward();
					_view.rewardPanel.updateHint("你今日已无法领奖。");
					break;
				case "-3":
					_control.playerInfoModulControl.disableReward();
					_view.rewardPanel.updateHint("你正在打牌中，不能领取。");
					break;
			}
			
			if (int(content.@des.toString()) >= 0)
			{
				_view.rewardPanel.switchLayer(1);
				_view.rewardPanel.updateMoney(content.@des.toString());
				_control.playerInfoModulControl.disableReward();
			}
		}
		
		public function onSendVeryCode(content:String):void
		{
			if (StringUtils.trim(content).length <= 0)
			{
				return;
			}
			
			loadXmlMsg = new XmlLoadMessage(onSendBack);
			loadXmlMsg.url = GameState.getServerLink() + "40&key=" + GameState.snsKey + "&verifycode=" + content;
			loadXmlMsg.send();
			_control.alertPanelControl.alert("发送验证码中，请稍等...");
		}
		
		public function open():void
		{
			refresh();
			_view.rewardPanel.open();
		}
		
		public function refresh():void
		{
			loadMsg = new DisplayObjectLoadMessage(onVeryCodeComplete);	
			loadMsg.isCompress = true;
			loadMsg.url =   GameState.getServerLink() + "39&key=" + GameState.snsKey ;
			loadMsg.send();
	
		}
		
	}
}